/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief MaCI - Parameter Interface Client header
 * \author Matthieu Myrsky <matthieu.myrsky@tkk.fi>
 *
 * $Id: ParameterClient.hpp,v 1.2 2009-12-08 10:48:28 morsko Exp $
 *
 */
#ifndef _MACI_INTERFACE_PARAMETERCLIENT_HPP_
#define _MACI_INTERFACE_PARAMETERCLIENT_HPP_

#include "MaCI.hpp"
#include "ParameterXML.hpp"

// These are not necessarily required here, but defined to make the
// interface easier to include.
#include "ParameterData.hpp"

// Forward declare gimi::GIMI
namespace gimi {
  class GIMI;
}

namespace MaCI {
  namespace Parameter {
    
    

    /** MaCI - Parameter Client interface.
     * 
     * This class contains the methods and types for using
     * a MaCI::Parameter service in the GIMnet.
     */
    class CParameterClient 
      : public MaCI::CMaCI
    {
    public:
      /** Constructor.
       * 
       * Constructor of the ParameterClient. This requires;
       * a pointer to Initialized and connected GIMI, minor
       * number of this interface (Used as GIMI minor number)
       *
       * @param[in] aGIMIPtr Pointer to GIMI used for communication
       * @param[in] aInterfaceMinor Interface minor number. Usually
       *            used to indicate the instance of devices of same
       *            type. Can be left out if MaCISL is used.
       */     
      CParameterClient(gimi::GIMI *aGIMIPtr, const int aInterfaceMinor = -1);

      
      /** Destructor.
       */
      ~CParameterClient();


      /** Execute Parameter Query synchronously.
       *
       * This function attempts to execute a Parameter query
       * synchronously. This means that the function will sit back and
       * wait until a reply is available or time limit is hit.
       *
       * \note This function is implemented as calling the SendQuery()
       * and GetQueryResult() in sequence, and gives no performance
       * benefits (or hit) for using it instead.
       *
       * @param[out] aParameterList    Resulting data is stored here.
       * @param[in] aTimeout_ms        Time allowed for this operation
       * @return                       true if list saved, otherwise(timeout etc) false
       */
      bool GetParameterList(TParameterInfoArray &aParameterList,
                            const unsigned int aTimeout_ms = 3000);


      /** Send Parameter Query Synchronously.
       *  
       * @param[in] aParameterToSet     TParm-structure to set
       * @return                        'true' when sent succesfully, 'false' on
       *                                container or 'Send' error.
       */
      bool SetParameter(const TParam &aParameterToSet);
      
      


    protected:
      /** Open client interface.
       *
       * Implementation of Open() for the class. This function is
       * called by the base class CMaCI::Open() function.
       */
      EMaCIError DoOpen(void);
      
      
      /** Close client interface.
       *
       * Implementation of Close() for the class. This function is
       * called by the base class CMaCI::Close() function.
       */
      EMaCIError DoClose(void);


    private:
       
     
      // Override copy & assignment operator privately to disable class copying.
      CParameterClient(const CParameterClient &)
        : CMaCI(NULL, 0, 0, "")
      {}
     
      CParameterClient &operator=(const CParameterClient &) { return *this; }
    };


  }
}

#endif //_MACI_INTERFACE_PARAMETERCLIENT_HPP_
